//
//  ZYCApplianceBannerView.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/20.
//

#import "ZYCApplianceBannerView.h"
#import <SDCycleScrollView.h>
#import "ZYCWheelBannerModel.h"
@interface ZYCApplianceBannerView ()<SDCycleScrollViewDelegate>

@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation ZYCApplianceBannerView

- (void)setSection:(NSString *)section{
    _section = section;
    _titleLabel.text = section;
}

- (void)setWheelBannerList:(NSArray *)wheelBannerList{
    _wheelBannerList = wheelBannerList;
    NSMutableArray *tempArr = [NSMutableArray arrayWithCapacity:0];
    for (ZYCWheelBannerModel *model in wheelBannerList) {
        NSString *imgUrl = [[NSString stringWithFormat:@"%@/zd-system-service%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"sdfz_url"],model.path] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        [tempArr addObject:imgUrl];
    }
    _cycleScrollView.imageURLStringsGroup = tempArr.copy;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.titleLabel];
        [self addSubview:self.cycleScrollView];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(9.0f);
            make.top.equalTo(self).offset(30.0f);
        }];
        
        [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(9.f);
            make.right.offset(-9.f);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(10.0f);
            make.height.mas_equalTo((kScreenWidth - 18) / (710 / 300));
        }];
    }
    return self;
}

- (SDCycleScrollView *)cycleScrollView {
    if (!_cycleScrollView) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"banner"]];
        _cycleScrollView.showPageControl = YES;
        _cycleScrollView.autoScrollTimeInterval = 3.0f;
        _cycleScrollView.backgroundColor = [UIColor clearColor];
        _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
        _cycleScrollView.currentPageDotColor = [UIColor colorWithHexString:kBgGreenColor alpha:1.0];
        _cycleScrollView.pageDotColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1.0];
        _cycleScrollView.layer.cornerRadius = 5.0f;
        _cycleScrollView.layer.masksToBounds = YES;
    }
    return _cycleScrollView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithString:@"智慧门户" Font:kSystemBoldFont(16.0f) titleColor:HEX_RGB(kTitleDrakBlackColor) textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}

#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    if ([self.delegate respondsToSelector:@selector(applianceBannerViewDidClickBanner:)]) {
        [self.delegate applianceBannerViewDidClickBanner:self.wheelBannerList[index]];
    }
}

/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index{
    
}

@end
